﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace medicine.Forms.ItemSelection
{
    public partial class ItemSelectionFindFRM : Form
    {
        public enum eFindMode
        {
            AnyWhere,
            Beginning,
            end
        };

        public eFindMode FindMode
        {
            get;
            set;
        }

        public bool MatchCase = false;
        public string FilterText { get; set; }

        public static object[] HistoryList;
        public ItemSelectionFindFRM()
        {
            InitializeComponent();
        }

        private void cmdFindAll_Click(object sender, EventArgs e)
        {
            if (cmbSearchText.Text == string.Empty)
            {
                errorProvider1.SetError(cmbSearchText, "Required Value");
                return;
            }
            //-----------------------------------------------------
            // history
            if (!cmbSearchText.Items.Contains(cmbSearchText.Text))
            {
                cmbSearchText.Items.Add(cmbSearchText.Text);
                object[] temp = new object[cmbSearchText.Items.Count];
                int i = 0;
                foreach (object item in cmbSearchText.Items)
                {
                    temp[i] = item;
                    i++;
                }
                HistoryList = temp;
            }

            //-----------------------------------------------------
            this.DialogResult = DialogResult.OK ;
            if (rdAnywhere.Checked)
                this.FindMode = eFindMode.AnyWhere;
            if (rdBeginning.Checked)
                this.FindMode = eFindMode.Beginning;
            if (rdEnd.Checked)
                this.FindMode = eFindMode.end;
            this.MatchCase = chkMatchCase.Checked;
            this.FilterText = cmbSearchText.Text;
            //-----------------------------------------------------
            this.Close();
        }

        private void cmdClose_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel ;
            this.Close();
        }

        private void ItemSelectionFindFRM_Load(object sender, EventArgs e)
        {
            cmbSearchText.Items.Clear();
            if (HistoryList!=null)
                cmbSearchText.Items.AddRange(HistoryList);
        }
    }
}
